package org.highapplication.nineapp.activitiy;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import org.highapplication.nineapp.Post;
import org.highapplication.nineapp.R;
import org.highapplication.nineapp.fragment.HomepageFragment;
import org.highapplication.nineapp.fragment.NineYuanFragment;
import org.highapplication.nineapp.fragment.PersonalCenterFragment;
import org.highapplication.nineapp.fragment.SpecialOfferFragment;
import org.highapplication.nineapp.fragment.WorthAroundFragment;

public class   MainActivity extends AppCompatActivity implements Post {
    private View lastView;
    private int position_click;
    private String Url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lastView = findViewById(R.id.btn_headpage);
        lastView.setClickable(false);
        lastView.setSelected(true);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomepageFragment()).addToBackStack(null).commit();
    }

    public void onClick(View view){
        //判断是否是第一次点击
            switch (view.getId()){
                case R.id.btn_headpage :
                    chageState(view);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomepageFragment()).commit();
                    break;
                case R.id.btn_specialoffer:
                    chageState(view);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SpecialOfferFragment()).commit();
                    break;
                case R.id.btn_nineyuan:
                    chageState(view);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NineYuanFragment()).commit();
                    break;
                case R.id.btn_wortharound:
                    chageState(view);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new WorthAroundFragment()).commit();
                    break;
                case R.id.btn_personalcenter:
                    chageState(view);
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PersonalCenterFragment()).commit();
                    break;

        }

    }

    public void click(View view){
        if(view !=null){
            switch (view.getId()){
                case R.id.imgbtn_register_set:
                    //Toast.makeText(this,"设置",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this,SetActivity.class));
                    break;
                case R.id.btn_register:
                    //Toast.makeText(this,"登录",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this,RegisterActivity.class));
                    break;
                case R.id.btn_personalcenter_sex:
                    // Toast.makeText(this,"帅哥",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this,PersonalcenterSexActivity.class));
                    break;
                case R.id.btn_taobao_list_personalcenter:
                    //Toast.makeText(this,"淘宝订单",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this,TaoBaoListActivity.class));
                    break;
                case R.id.btn_taobao_transport_personalcenter:
                    // Toast.makeText(this,"淘宝物流信息",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, TaoBaoTransportActivity.class));
                    break;
                case R.id.btn_taobao_shopcars_personalcenter:
                    // Toast.makeText(this,"淘宝购物车",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, TaoBaoShopcarsActivity.class));
                    break;
                case R.id.btn_mCollect_personalcenter:
                    // Toast.makeText(this,"我的收藏",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, MyCollectActivity.class));
                    break;
                case R.id.btn_sign_in_personalcenter:
                    //Toast.makeText(this,"签到领积分",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, SignInActivity.class));
                    break;
                case R.id.btn_mIntegral_personalcenter:
                    //Toast.makeText(this,"我的积分",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, MyIntegralActivity.class));
                    break;
                case R.id.btn_shopIntegral_personalcenter:
                    //Toast.makeText(this,"积分商城",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(this, ShopIntegralActivity.class));
                    break;
            }
        }

    }




    //改变当前点击状态并记录以便下一次使用
    public void chageState(View view){
        lastView.setSelected(false);
        lastView.setClickable(true);
        view.setSelected(true);
        view.setClickable(false);
        lastView = view;
    }

    @Override
    public void post(String url) {
        Url = url;
    }
}
